home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / fstwait.com / WAIT.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-04-08  |  2.0 KB  |  107 lines

  1. ;══════════════════════════════════════════════════════ Data
  2.  
  3. DATA SEGMENT BYTE PUBLIC
  4.  
  5.     EXTRN    WaitOneMS        : word
  6.     EXTRN    LoopsPerTick    : dword
  7.  
  8. DATA    ENDS
  9.  
  10. ;══════════════════════════════════════════════════════ Code
  11.  
  12. CODE    SEGMENT BYTE PUBLIC
  13.  
  14.        ASSUME  CS:CODE, DS:DATA
  15.  
  16.        PUBLIC  WaitInit, Wait
  17.  
  18.  
  19. ;══════════════════════════════════════════════════════ WaitMS
  20.  
  21. ;Delay one millisecond
  22.  
  23. WaitMS    PROC NEAR
  24.  
  25.     cmp    al,es:[di]
  26.     jne    WaitMSexit
  27.     loop WaitMS
  28. WaitMSexit:
  29.     ret
  30.  
  31. WaitMS    ENDP
  32.  
  33.  
  34. ;══════════════════════════════════════════════════════ Wait
  35.  
  36. ;procedure Wait(MS: Word);
  37. ;Delay for MS milliseconds
  38.  
  39. MSecs    EQU    WORD PTR SS:[BX+4]
  40.  
  41. Wait    PROC FAR
  42.  
  43.     mov    bx,sp
  44.     mov    dx,MSecs        ;DX = MS
  45.     or    dx,dx        ;Do nothing if MS = 0
  46.     jz    WaitExit
  47.     xor    di,di        ; ES:DI points to dummy address
  48.     mov    es,di        ;  which won't change
  49.     mov    al,es:[di]    ; AL has the value there
  50.     mov    bx,WaitOneMS    ; BX has loop count for one MS
  51.  
  52. DelayLoop:
  53.     mov    cx,bx        ; loop count into CX
  54.     call WaitMS        ; delay for one MS
  55.     dec    dx            ; decrement counter
  56.     jnz    DelayLoop        ; repeat if not 0
  57.  
  58. WaitExit:
  59.     ret    2
  60.  
  61. Wait    ENDP
  62.  
  63.  
  64.  
  65. ;══════════════════════════════════════════════════════ WaitInit
  66.  
  67.  
  68. ;procedure WaitInit;
  69.  
  70. WaitInit    PROC NEAR
  71.  
  72.       ;set up delay count
  73.     mov    ax,40h                ; ax = $40
  74.     mov    es,ax                ; es = $40
  75.     mov    di,6Ch                ; es:di => low word of BIOS timer count
  76.     mov    cx,0FFFFh                ; loop before the timer count changes
  77.     xor    dx,dx
  78.     mov    al,es:[DI]            ; al has first byte there
  79. WaitForChange:
  80.     cmp    al,es:[di]            ; wait for the byte to change
  81.     jz    WaitForChange
  82.  
  83.     mov    al,es:[di]            ; see how many times to
  84.                             ;  loop before the timer count changes
  85. @@1:
  86.     cmp    al,es:[di]
  87.     jne    @@2
  88.     loop @@1
  89.     inc    dx                    ; for more than 65535 loops (fast PC)
  90.     jmp    short @@1
  91. @@2:
  92.  
  93.     mov    ax,55                ; now calculate OneMS
  94.     xchg cx,ax
  95.     not    ax
  96.     mov    word ptr [LoopsPerTick],ax
  97.     mov    word ptr [LoopsPerTick + 2],dx
  98.     div    cx
  99.     mov    WaitOneMS,ax            ; ax has OneMS
  100.     ret
  101.  
  102. WaitInit    ENDP
  103.  
  104. CODE    ENDS
  105.  
  106.     END
  107.